function Point(){
    this.x=Math.random()*950+25;
    this.y=Math.random()*900+50;
}
function freePoint(x, y) {
    this.x=x;
    this.y=y;
}

function closeTO(p1, p2, sp) {
    var r=getAngle(p1,p2);
    return toRod(p1,sp,r);
}

function getAngle(p1,p2) {
    return Math.atan2(p2.y-p1.y,p2.x-p1.x);
}

function offPTP(p1,p2) {
    var dx=p2.x-p1.x;
    var dy=p2.y-p1.y;
    return Math.sqrt(dx*dx+dy*dy);
}

function toRod(p,l,r) {
    var x=p.x+l*Math.cos(r);
    var y=p.y+l*Math.sin(r);
    return new freePoint(x,y);
}

function toFace(r,time) {
    var pi=Math.PI;
    if(r>pi/8&&r<pi*3/8){
        I.face=5;
    }else if(r>pi*3/8&&r<pi*5/8){
        I.face=0;
    }else if(r>pi*5/8&&r<pi*7/8){
        I.face=4;
    }else if(r>pi*7/8||r<-pi*7/8){
        I.face=1;
    }else if(r>pi*-7/8&&r<pi*-5/8){
        I.face=6;
    }else if(r>-pi*5/8&&r<-pi*3/8){
        I.face=3;
    }else if(r>pi*-3/8&&r<-pi/8){
        I.face=7;
    }else if(r>-pi/8&&r<pi/8){
        I.face=2;
    }
    if(time){
        setTimeout(function () {
            shoot=false;
        },time);
    }
}

function MPoint(e) {
    var x=e.offsetX/timesX;
    var y=e.offsetY/timesY;
    return new freePoint(x,y);
}

function drawRestart(i){
    if(i<=0)return;
    MyImgCode=0;
    cxt.font=50+"px 微软雅黑";
    cxt.save();
    cxt.beginPath();
    cxt.fillStyle="#555";
    cxt.textAlign="center";
    cxt.textBaseline="middle";
    cxt.fillText("你已经阵亡",500,400);
    cxt.font=100-i%1000/20+"px 微软雅黑";
    cxt.fillText(Math.floor(i/1000)+"秒后复活",500,500);
    cxt.restore();
    resetTime-=deltaTime;
}